package io.renren.modules.powercut.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.modules.powercut.entity.dto.StandingbookDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.powercut.entity.StandingbookEntity;
import io.renren.modules.powercut.service.StandingbookService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletResponse;

/**
 * 停电台账
 *
 * @author zhujinbo 1724282894@qq.com
 * @email 1724282894@qq.com
 * @date 2020-12-05 11:22:28
 */
@RestController
@RequestMapping("powercut/standingbook")
@Api("停电台账")
public class StandingbookController {
    @Autowired
    private StandingbookService standingbookService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("powercut:standingbook:list")
    @ApiOperation("列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = standingbookService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 导出
     */
    @GetMapping("exprtStandingBook")
    @ApiOperation("导出")
    @RequiresPermissions("powercut:standingbook:exprt")
    public void exportStandingBook(@RequestParam(required = false) Map<String, Object> params, HttpServletResponse response){
        standingbookService.exportStandingBook(params,response);
    }

    /**
     * 清空
     */
    @DeleteMapping("/empty")
    @RequiresPermissions("powercut:affectdistrict:empty")
    public R empty(){
        QueryWrapper<StandingbookEntity> standingbookEntityQueryWrapper = new QueryWrapper<>();
        standingbookService.remove(standingbookEntityQueryWrapper);
        return R.ok();
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("powercut:standingbook:info")
    @ApiOperation("信息")
    public R info(@PathVariable("id") String id){
        StandingbookDto standingbookDto =  standingbookService.queryStandingbookInfo(id);
        return R.ok().put("standingbookDto",standingbookDto);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("powercut:standingbook:save")
    public R save(@RequestBody StandingbookEntity standingbook){
		standingbookService.save(standingbook);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("powercut:standingbook:update")
    public R update(@RequestBody StandingbookEntity standingbook){
		standingbookService.updateById(standingbook);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("powercut:standingbook:delete")
    public R delete(@RequestBody String[] ids){
		standingbookService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
